/*
 * @Description: 备考表按钮
 * @Author: Zzt
 * @Date: 2023-01-12 10:03:09
 * @LastEditTime: 2023-01-29 18:04:25
 */
import { getFileNote } from '@/api/archives/operate';
import ProForma from '@/components/LevelLayout/components/dialogs/ProForma';
import { Button } from 'antd';
import { useEffect, useMemo, useState } from 'react';

const ProFormaBtn = (props: any) => {
  const { data, baseInfo } = props;
  const [proFormaVisible, setProFormaVisible] = useState(false);
  const [proData, setProData] = useState({});

  const ProFormaForm = (data: any) => {
    const location = {
      atCode: baseInfo.atCode,
      atType: baseInfo.atType,
      dbName: baseInfo.dbName
    };
    // 准备备考表内容
    /* 掉个接口在这里 */
    getFileNote({ entryId: data.id, ...location }).then((res) => {
      const { data } = res;
      setProData(data);
      setProFormaVisible(true);
    });
  };
  return (
    <>
      <Button
        onClick={(evt) => {
          evt.stopPropagation();
          ProFormaForm(data);
        }}
        type="link"
      >
        备考表
      </Button>
      {useMemo(
        () => (
          <ProForma
            visible={proFormaVisible}
            data={proData}
            baseInfo={baseInfo}
            type={1}
            onClose={() => setProFormaVisible(false)}
          />
        ),
        [proFormaVisible, proData]
      )}
    </>
  );
};
export default ProFormaBtn;
